// Package security Package tools @program: account
//@author: edte
//@create: 2021-12-27 21:19
package security

import (
	"crypto/md5"
	"errors"
	"fmt"
	"io"
)

// Md5 Md5加密
func Md5(str string) (string, error) {
	var err error = nil
	//str传入要加密的字符串
	h := md5.New()
	_, err = io.WriteString(h, str)
	if err != nil {
		return "", errors.New("md5加密失败")
	}
	return fmt.Sprintf("%x", h.Sum(nil)), err
}
